﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;


namespace YXShop.TemplateAction
{
    public partial class LabelParse
    {
        public string Search()
        {
            string reStr = string.Empty;
            string mystyle = this.Label_Inserted;
            string str_Option = this.GetParamValue("YX:Option");
            switch (str_Option)
            {
                case "ProductSearch":
                    string strContent = mystyle;
                    if (!string.IsNullOrEmpty(mystyle))
                    {

                        if (!string.IsNullOrEmpty(mystyle))
                        {
                            if (strContent.IndexOf("[#Cond_Key]") > -1)
                            {
                                strContent = strContent.Replace("[#Cond_Key]", "<input type=\"text\" name=\"q_prokey\" id=\"q_prokey\"></input>");
                            }
                            if (strContent.IndexOf("[#Cond_ProName]") > -1)
                            {
                                strContent = strContent.Replace("[#Cond_ProName]", "<input type=\"text\" name=\"q_proname\" id=\"q_proname\"></input>");
                            }
                            if (strContent.IndexOf("[#Cond_ProClass]") > -1)
                            {
                                StringBuilder sbClass = new StringBuilder();
                                sbClass.Append("<select id=\"q_proclassid\" name=\"q_proclassid\">");
                                sbClass.Append("<option value=\"\">所有分类</option>");
                                YXShop.BLL.Product.Productclass pcbll = new YXShop.BLL.Product.Productclass();
                                DataTable pcdt = pcbll.GetFatherList(0);
                                if (pcdt.Rows.Count > 0)
                                {
                                    for (int c = 0; c < pcdt.Rows.Count; c++)
                                    {
                                        sbClass.Append("<option value=\"" + pcdt.Rows[c]["cid"].ToString() + "\">" + pcdt.Rows[c]["name"].ToString() + "</option>");
                                    }
                                }
                                sbClass.Append("</select>");
                                strContent = strContent.Replace("[#Cond_ProClass]", sbClass.ToString());
                            }
                            if (strContent.IndexOf("[#Cond_ProBrand]") > -1)
                            {
                                StringBuilder sbBrand = new StringBuilder();
                                sbBrand.Append("<select id=\"q_probrandid\" name=\"q_probrandid\">");
                                sbBrand.Append("<option value=\"0\">所有品牌</option>");
                                YXShop.BLL.Product.ProductBrand data = new YXShop.BLL.Product.ProductBrand();
                                ChangeHope.DataBase.DataByPage dataPage = data.GetList();

                                if (dataPage.DataReader != null)
                                {
                                    while (dataPage.DataReader.Read())
                                    {
                                        sbBrand.Append("<option value=\"" + dataPage.DataReader["bid"].ToString() + "\">" + dataPage.DataReader["name"].ToString() + "</option>");
                                    }
                                }

                                sbBrand.Append("</select>");
                                strContent = strContent.Replace("[#Cond_ProBrand]", sbBrand.ToString());
                            }
                            if (strContent.IndexOf("[#Cond_Price]") > -1)
                            {
                                strContent = strContent.Replace("[#Cond_Price]", "<input type=\"text\" name=\"q_proprice1\" id=\"q_proprice1\" width='50px'></input>&nbsp;至&nbsp;<input type=\"text\" name=\"q_proprice2\" id=\"q_proprice2\" width='50px'></input>");
                            }
                            if (strContent.IndexOf("[#Cond_State]") > -1)
                            {
                                string In = "<input type=\"radio\" name=\"q_attribute\" value=\"1\">推荐商品  <input type=\"radio\" name=\"q_attribute\" value=\"3\">热卖商品<input type=\"radio\" name=\"q_attribute\" value=\"5\"> 特价商品<input type=\"radio\" name=\"q_attribute\" value=\"9\">最新商品</ul>";
                                strContent = strContent.Replace("[#Cond_State]", In);
                            }
                            if (strContent.IndexOf("[#Cond_Content]") > -1)
                            {
                                strContent = strContent.Replace("[#Cond_Content]", "<input type=\"text\" name=\"q_procontent\" id=\"q_procontent\"></input>");
                            }
                            if (strContent.IndexOf("[#Cond_No]") > -1)
                            {
                                strContent = strContent.Replace("[#Cond_No]", "<input type=\"text\" name=\"q_prono\" id=\"q_prono\"></input>");
                            }
                            if (strContent.IndexOf("[#Option_Src]") > -1)
                            {
                                strContent = strContent.Replace("[#Option_Src]", "<input id=\"Submit1\" Class=\"SubSearch\" type=\"submit\" value=\"搜 索\" />");
                            }
                            if (strContent.IndexOf("[#Option_Reste]") > -1)
                            {
                                strContent = strContent.Replace("[#Option_Reste]", "<input id=\"Reset1\" type=\"reset\" value=\"重 写\" />");
                            }
                        }
                    }
                    reStr = strContent;
                    break;
            }
            
            return reStr;
        }
    }
}
